package in.smartride.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
import com.google.gwt.user.datepicker.client.DateBox;

public class EditPreferences implements Command {

	@Override
	public void execute() {
		RootPanel.get().clear();
		SmartRide.addBar();
		// Create a table to layout the form options
		final FlexTable layout = new FlexTable();
		layout.setCellSpacing(6);
		FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();

		// Add a title to the form
		layout.setHTML(0, 0, "Edit Preferences");
		cellFormatter.setColSpan(0, 0, 2);
		cellFormatter.setHorizontalAlignment(0, 0,
				HasHorizontalAlignment.ALIGN_CENTER);

		// Add some standard form options
		layout.setHTML(1, 0, "sex");
		HorizontalPanel sex = new HorizontalPanel();

		RadioButton male = new RadioButton("sex");
		RadioButton female = new RadioButton("sex");
		RadioButton any = new RadioButton("sex");
		sex.add(male);
		sex.add(new HTML("male"));
		sex.add(female);
		sex.add(new HTML("female"));
		sex.add(any);
		sex.add(new HTML("any"));
		layout.setWidget(1, 1, sex);

		layout.setHTML(2, 0, "Age Group");
		HorizontalPanel age = new HorizontalPanel();
		ListBox min = new ListBox(false);
		for (int i = 18; i <= 60; i += 5) {
			min.addItem(i + "");
		}
		ListBox max = new ListBox(false);
		for (int i = 18; i <= 60; i += 5) {
			max.addItem(i + "");
		}
		max.setSelectedIndex(8);
		age.add(min);
		age.add(max);
		layout.setWidget(2, 1, age);
		layout.setHTML(3, 0, "wait");
		TextBox temp = new TextBox();
		temp.setReadOnly(true);
		ListBox wait = new ListBox(false);
		for (int i = 0; i <= 60; i += 10) {
			wait.addItem(i + "");
		}
		wait.setSelectedIndex(3);
		layout.setWidget(3, 1, wait);
		// layout.setHTML(4, 0, "---");
		// layout.setWidget(4, 1, temp);
		// layout.setHTML(5, 0, "---");
		// layout.setWidget(5, 1, temp);
		// add a button
		Button save = new Button("save");
		save.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				HTML text = new HTML("updates are saved!!", true);
				layout.setWidget(6, 0, text);
			}
		});
		layout.setWidget(7, 0, save);
		cellFormatter.setColSpan(7, 0, 2);
		cellFormatter.setHorizontalAlignment(7, 0,
				HasHorizontalAlignment.ALIGN_CENTER);

		// Wrap the content in a DecoratorPanel
		layout.setWidth(SmartRide.width / 3 + "px");
		layout.setHeight(SmartRide.height / 2 + "px");
		DecoratorPanel decPanel = new DecoratorPanel();
		decPanel.setWidget(layout);
		RootPanel.get()
				.add(decPanel, SmartRide.width / 3, SmartRide.height / 4);
	}

}
